#include "mpuiic.h"

void MPU_IIC_Init(void)
{
	GPIO_InitTypeDef GPIO_InitStructure;
	I2C_InitTypeDef I2C_InitStructure;

	//Enable the clock
	RCC_APB1PeriphClockCmd( MPU_I2C_RCC_APB1_CLOCK, ENABLE);	
	RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOB, ENABLE );
	//Configuration I2C
	GPIO_InitStructure.GPIO_Pin = MPU_I2C_SCL_PIN | MPU_I2C_SDA_PIN;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD;
	GPIO_Init(MPU_I2C_GPIO, &GPIO_InitStructure);	
	//Configure I2C
	I2C_InitStructure.I2C_Mode = I2C_Mode_I2C;
	I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2;
	I2C_InitStructure.I2C_OwnAddress1 = 0x10;                                   
	I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;
	I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
	I2C_InitStructure.I2C_ClockSpeed = 200000;	
	I2C_Init(MPU_I2C_USED, &I2C_InitStructure);
	I2C_AcknowledgeConfig(MPU_I2C_USED, ENABLE);
	I2C_Cmd(MPU_I2C_USED, ENABLE);
//	SEGGER_RTT_printf(0, "MPU_IIC_Init ok @@@@@@@@@@@\r\n");
}

